﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Zwms.Client.CommonUI
{
    public partial class DatePickerUC : UserControl
    {
        private string _selectDateTime ="";
        public string SelectDateTime
        {
            get
            {
                return _selectDateTime;
            }
            set
            {
                _selectDateTime = value;
            }
        }
        public DatePickerUC()
        {
            InitializeComponent();
            _selectDateTime = "";
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.SelectDateTime = "";
            this.tbContent.Text = "";
        }

        private void dtpSelect_ValueChanged(object sender, EventArgs e)
        {
            this.tbContent.Text = string.Format("{0:yyyy-MM-dd}", dtpSelect.Value);
            this.SelectDateTime = string.Format("{0:yyyyMMdd}", dtpSelect.Value);
        }

        public void SetDate(DateTime dt)
        {
            if (dt.CompareTo(new DateTime(1900, 1, 1)) != 0)
            {
                SelectDateTime = string.Format("{0:yyyyMMdd}", dt);
                this.tbContent.Text = string.Format("{0:yyyy-MM-dd}", dt);
            }
            else
            {
                SelectDateTime = string.Empty;
                this.tbContent.Text = string.Empty;
            }
        }

        public void SetVoidDate()
        {
            SelectDateTime = string.Empty;
            this.tbContent.Text = string.Empty;
        }

        public void SetEditState(bool b)
        {
            dtpSelect.Enabled = b;
            btnClear.Enabled = b;
        }

        public void SetTextBGColor(Color c)
        {
            this.tbContent.BackColor = c;
        }
    }
}
